I:/Documents/developpement/projets/C/blast/blastguy_wii_2.2/src/unit.h File Reference

A unit is a game specific entity, it's attribut vary from one game to an other, but it's use an anim_sprite and got velocity. More...

#include <stdlib.h>
#include <stdio.h>
#include <SDL/sdl.h>
#include "sprite.h"
#include "bomb.h"
#include "map.h"
#include "image.h"
#include "sdl_utils.h"

Include dependency graph for unit.h:

This graph shows which files directly or indirectly include this file:


Data Structures

struct  t_unit
 A unit is a game specific entity, it's attribut vary from one game to an other, but it's use an anim_sprite and got velocity. More...

Enumerations

enum  e_actions
 directions of a unit, and other actions possible More...

Functions

void minsort (unit **tab, size_t size)
 sort unit tab for z_index order
void unit_draw (unit *p_unit, SDL_Surface *destination)
 Draw a unit to the given surface.
void unit_draw_from_z_index (unit **v_unit, const int unit_nb, SDL_Surface *destination)
 Draw units to the given surface, sorted by coord_y. A unit with a lower coord_y will be blit first, this avoid that a unit can walk above the head of another unit, it's a purly cosmetic function.
void unit_update (unit *p_unit, map *p_map)
 Call updates functions (check wall, bombs, etc).
void unit_update_frame (unit *p_unit)
 Update the frame of the unit, call anim_sprite_update_frame when a move is detected by checking the velocity.
void unit_update_position (unit *p_unit)
 Update the unit coords according to it's velocity.
struct bomb_t * unit_put_bomb (unit *p_unit, map *p_map)
 Put a bomb to the map.
int unit_y_compare (void const *a, void const *b)
 Compare the z_index of units.
void unit_set_vel_x (unit *p_unit, int value)
 Set the x velocity of a unit.
void unit_set_vel_y (unit *p_unit, int value)
 Set the y velocity of a unit.
int unit_get_x (unit *p_unit)
 Get the x coord of the unit.
int unit_get_y (unit *p_unit)
 Get the y coord of the unit.
int unit_get_index_x (unit *p_unit)
 Get the x index of the unit.
int unit_get_index_y (unit *p_unit)
 Get the y index of the unit.
void unit_check_tile (unit *p_unit, map *p_map)
 Check if the unit can move on tiles (is_walckable ? ).
void unit_check_bomb (unit *p_unit, map *p_map)
 Check if the unit can move on a bomb.
SDL_Rect unit_get_bounding_box (unit *p_unit)
 Get the bounding box of a unit.
int unit_get_bounding_center_x (unit *p_unit)
 Get the x coord of the center of the bounding box.
int unit_get_bounding_center_y (unit *p_unit)
 Get the y coord of the center of the bounding box.
int unit_get_bounding_index_center_x (unit *p_unit)
 Get the x coord of the center of the bounding box.
int unit_get_bounding_index_center_y (unit *p_unit)
 Get the y coord of the center of the bounding box.
void unit_tile_protect (unit *p_unit, map *p_map, int direction)
 Set flag protected in the map around a unit, no block can be placed in a protected tile, in order to allow a unit to move at the begining of the battle. The tile protection must make a corner or a line longeur than the unit fire power.
int unit_check_victory (unit **v_unit, int unit_nb)
 Check if a unit in the array is vicrorious (i.e. the only not dead).
void unit_init (unit **v_unit, int unit_nb)
 Give to unit a lot of hard coded values (animation key, key binding, speed, bomb left...) Theses values will be soon in a file to load and save theme, but I did make any editor yet...

Detailed Description

A unit is a game specific entity, it's attribut vary from one game to an other, but it's use an anim_sprite and got velocity.

Author:
DREVET Olivier
Date:
September and October 2008
Note:
ANSI c90 compliance. Published under the GPL 3 license (see license.txt for more info)

Enumeration Type Documentation

enum e_actions

directions of a unit, and other actions possible

Note:
Mainly used for animations
Parameters:
NO_WAY_OUT When the unit cannot move to another tile, other are self explanitory


Function Documentation

void unit_check_bomb ( unit p_unit,
map p_map 
)

Check if the unit can move on a bomb.

Note:
The unit can move on this own bomb when he just have drop it. I've found some solutions to find how to do this. My favourite is to compare the index of the center of the unit and the index of the bounding box side unit direction. If index (tile number) are differant, the unit has move to far and the bomb collision detection is made. If the center index and the side index is the same, it's mean that the unit is on his own bomb, and he can move.
There is the pseudo code :

Algo unit_check_bomb Begin If the unit velocity is <= 1 // Moving to the left If the Center of the unit index at x is differant of the Index from the x left side of the bounding box AND If the map tile at the left side index of the bounding box is a bomb Then Go to previous position (move is not allowed) End If End

The same goes for other directions, the side and the previous position changed. Remember that x and y coord are given from the left top side, for check when the unit move down or right, the height or the width of the bounding box must be added (see source for more info). Use a pice of paper, draw the map and the unit bounding box with a dot at his center, follow the pseudo code and you will understand how it works.

void unit_check_tile ( unit p_unit,
map p_map 
)

Check if the unit can move on tiles (is_walckable ? ).

Note:
This also include a smooth move routine

int unit_check_victory ( unit **  v_unit,
int  unit_nb 
)

Check if a unit in the array is vicrorious (i.e. the only not dead).

Returns:
-1 if all units are dead (draw) -2 if more than one unit are alive Or the unit position in the v_unit vector the this is the only unit alive (the victorious unit) from 0

void unit_draw ( unit p_unit,
SDL_Surface *  destination 
)

Draw a unit to the given surface.

Parameters:
Unit to draw
Surface where draw

void unit_draw_from_z_index ( unit **  v_unit,
const int  unit_nb,
SDL_Surface *  destination 
)

Draw units to the given surface, sorted by coord_y. A unit with a lower coord_y will be blit first, this avoid that a unit can walk above the head of another unit, it's a purly cosmetic function.

Parameters:
Units to draw
Number of units in the array
Surface where draw

SDL_Rect unit_get_bounding_box ( unit p_unit  ) 

Get the bounding box of a unit.

Parameters:
The unit
Returns:
The bounding box of the unit

int unit_get_bounding_center_x ( unit p_unit  ) 

Get the x coord of the center of the bounding box.

Parameters:
Unit holding the bounding box
Returns:
the center of the bounding box coord in x

int unit_get_bounding_center_y ( unit p_unit  ) 

Get the y coord of the center of the bounding box.

Parameters:
Unit holding the bounding box
Returns:
The center of the bounding box coord in y

int unit_get_bounding_index_center_x ( unit p_unit  ) 

Get the x coord of the center of the bounding box.

Parameters:
Unit holding the bounding box
Returns:
The center of the bounding box coord in x

int unit_get_bounding_index_center_y ( unit p_unit  ) 

Get the y coord of the center of the bounding box.

Parameters:
Unit holding the bounding box
Returns:
the center of the bounding box coord in y

int unit_get_index_x ( unit p_unit  ) 

Get the x index of the unit.

Note:
It's the x coord divided by TILE_SIZE

int unit_get_index_y ( unit p_unit  ) 

Get the y index of the unit.

Note:
It's the y coord divided by TILE_SIZE

struct bomb_t* unit_put_bomb ( unit p_unit,
map p_map 
) [read]

Put a bomb to the map.

Returns:
New bomb

void unit_set_vel_x ( unit p_unit,
int  value 
)

Set the x velocity of a unit.

Parameters:
unit to change the velocity
New velocity

void unit_set_vel_y ( unit p_unit,
int  value 
)

Set the y velocity of a unit.

Parameters:
Unit to change the velocity
New velocity

void unit_tile_protect ( unit p_unit,
map p_map,
int  direction 
)

Set flag protected in the map around a unit, no block can be placed in a protected tile, in order to allow a unit to move at the begining of the battle. The tile protection must make a corner or a line longeur than the unit fire power.

Parameters:
Direction to protect

void unit_update_position ( unit p_unit  ) 

Update the unit coords according to it's velocity.

Parameters:
Unit to update

int unit_y_compare ( void const *  a,
void const *  b 
)

Compare the z_index of units.

Note:
Used for blit order purpose, by unit_draw_from_z_index with a qsort on a copy of *v_unit


Generated on Tue Nov 4 21:07:26 2008 for Blastgu by  doxygen 1.5.4